﻿using UnityEngine;
using System.Collections;

public enum TCPEvent
{
    TcpConnect = ManagerID.NetManager + 1,
    TcpSendMsg,
    DisConnect,
    MaxValue
}

public class TCPConnectMsg : MsgBase
{
    public string ip;
    public ushort port;

    public TCPConnectMsg(ushort tmpId, string ip, ushort port) : base(tmpId)
    {
        this.msgId = tmpId;
        this.ip = ip;
        this.port = port;
    }
}

public class TcpMsg : MsgBase
{
    public NetMsgBase netMsg;
    public TcpMsg(ushort tmpid, NetMsgBase tmpBase) : base(tmpid)
    {
        this.msgId = tmpid;
        this.netMsg = tmpBase;
    }
}
public class TcpSocket : NetBase
{
    public override void ProcessEvent(MsgBase tmpMsg)
    {
        base.ProcessEvent(tmpMsg);

        switch ((TCPEvent)tmpMsg.msgId)
        {
            case TCPEvent.TcpConnect:

                TCPConnectMsg connectMsg = (TCPConnectMsg)tmpMsg;
                NetToServer = new NetWorkToServer(connectMsg.ip, connectMsg.port);

                break;
            case TCPEvent.TcpSendMsg:

                TcpMsg msg = (TcpMsg)tmpMsg;
                NetToServer.PutSendMsgPool(msg.netMsg);

                break;
        }
    }

    NetWorkToServer NetToServer;
    void Awake()
    {
        msgIds = new ushort[] {
            (ushort)TCPEvent.TcpConnect,
              (ushort)TCPEvent.TcpSendMsg,
        };

    }
}
